home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Sample Applications / Power Examples / SortPicts / Source / Traps.cp < prev    next >
Encoding:
Text File  |  1994-06-03  |  2.9 KB  |  83 lines  |  [TEXT/MPS ]

  1. /*************************************************************************************
  2.  *
  3.  *    Object Oriented Shell
  4.  *
  5.  *    Traps.cp - C Source
  6.  *
  7.  *      Copyright © Apple Computer, Inc. 1988 - 1993
  8.  *      All rights reserved.
  9.  *
  10.  *    This file has a bunch of test code to see if particular traps actually exist.
  11.  *      This is left over from two things: System 6.x and the 68K mac.
  12.  *      It's totally unnecessary if either of the above are unsupported.
  13.  *
  14.  *************************************************************************************/
  15.  
  16. #include "main.h"
  17. #include <Traps.h>
  18.  
  19. /**************************************************************************************
  20.  
  21.     TrapExists
  22.     
  23.     Check to see if a given trap is implemented.  The recommended approach to
  24.     see if a trap is implemented is to see if the address of the trap routine
  25.     is the same as the address of the unimplemented trap.  However, we must
  26.     also make sure that the trap is contained in the trap table on the machine
  27.     we're running on.  Not all Macintoshes have the same size trap tables.  We
  28.     call NumToolboxTraps to find out thje size of the table.   if the trap we are 
  29.     examing falls off the end, then we treat it as automatically being
  30.     unimplemented.
  31.     
  32. ***************************************************************************************/
  33. Boolean    TrapExists(short theTrap)
  34. {
  35.     TrapType    theTrapType;
  36.     
  37.     theTrapType = GetTrapType( theTrap);
  38.     if(( theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
  39.         return false;
  40.     else
  41.         return (NGetTrapAddress( _Unimplemented, ToolTrap) !=
  42.                 NGetTrapAddress( theTrap, theTrapType));
  43. }
  44.  
  45. /**************************************************************************************
  46.  
  47.     GetTrapType
  48.     
  49.     Check the bits of a trap number to determine its type.  If bit 11 is set,
  50.     it's a Toolbox trap.  Otherwise, it's an OS trap.
  51.     
  52. ***************************************************************************************/
  53. TrapType    GetTrapType(short theTrap)
  54. {
  55.     if(( theTrap & 0x0800) == 0)
  56.         return(OSTrap);
  57.     else
  58.         return(ToolTrap);
  59. }
  60.  
  61. /**************************************************************************************
  62.  
  63.     NumToolboxTraps
  64.     
  65.     Find the size of the Toolbox trap table.  This can be either 0x0200 or
  66.     0x0400 bytes, depending on which Macintosh we are running on.  We determine
  67.     the size by taking advantage of an anomaly of the smaller trap table: any
  68.     entries that fall byond the end of the trap table are mirrored back down into
  69.     the lower part.  For example, on a large table, trap numbers A86E and AA6E
  70.     correspond to different routines.  However, on a small table, they
  71.     correspond to the same routine address.  By chidking the addresses of these
  72.     routines, we can determine the size of the table.
  73.     
  74. ***************************************************************************************/
  75. short    NumToolboxTraps( void)
  76. {
  77.     if( NGetTrapAddress( 0xA86E, ToolTrap) == NGetTrapAddress( 0xAA6E, ToolTrap))
  78.         return( 0x0200);
  79.     else
  80.         return( 0x0400);
  81. }
  82.  
  83.